﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ page pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
	<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="pragma" content="no-cache"/>
	<meta http-equiv="expires" content="-1"/>    
	<script type="text/javascript">
        function on_dept_select(node){
          $('#updeptno').val(node.id);
          $('#updeptno_val').val(node.id);
          $('#typeid').combobox('reload', 
          	'queryDeptTypeList.action?typeid='+node.attributes);
          $('#deptno').focus();
        }
        function on_panel_close(){
          $("#sel_up_dept_pane").panel("destroy");
        }
    	$(document).ready(function(){
    		set_input_keydown_event();
    		$('#typeid').combobox({url:'queryDeptTypeList.action',onLoadSuccess:reset_typeid});
    		$('#depttree').tree({url:'queryDeptTree.action',onClick:on_dept_select,
    		  onLoadError: function(){alert('系统错误，服务器可能已关闭！')}});
    		combobox_keypress('#typeid','#deptaddr');
    		$('#sel_up_dept_pane').panel();
     		$('#add_dept_win').panel({onClose:on_panel_close});

     		$('#save').click(function (){
     		  $('#typeid_val').val($('#typeid').combobox('getValue'));
    		  $('#add_dept_form').form('submit', {url: 'addDept.action',
    		  	error:function(message){
    		    	alert('提交数据错误，服务器可能已关闭！系统返回:'+message);
    		  	},
    		    success:function(data){
    		     var a = eval('(' + data + ')');
    		      $.messager.alert('增加机构', a.message, 'info', 
    		        function(){$('#deptno').focus()});
    		      
    		      if (a.result == 0){
    		        var b=$('#depttree').tree('getSelected');
    		        var deptno=$('#deptno').val();
    		        var name=$('#deptname').val()+'['+deptno+']';
    		        if (b == null){    		   
    		        	$('#depttree').tree('append',{parent:null,
    		        		data:[{id:deptno,text:name,attributes:$('#typeid_val').val()}]});
    		        }
    		        else if (b.state!='closed'){
    		        	$('#depttree').tree('append',{parent:b.target,
    		        		data:[{id:deptno,text:name,attributes:$('#typeid_val').val()}]});
    		        }
    		      	$('#deptno').val('');
    		      	$('#deptname').val('');
    		      	$('#deptaddr').val('');
    		      	$('#telephone').val('');
    		      }
    		    }
    		    })
    		});

     		$('#cancel').click(function (){
     			$('#add_dept_win').panel('close');
    		});    		
    	});
    </script>
	</head>
	<body>

    <div id="add_dept_win" collapsible="false" fit="true" title="增加机构" resizable="false"
    	collapsible="false" minimizable="false" maximizable="false" closable="true" 
    	icon="icon-save" class="jquery_panel">
    	<s:form id="add_dept_form" theme="simple" action="addDept" cssStyle="margin:0px,0px">
    		<table height="94%">
    			<tr style="vertical-align: top">
    				<td width="280px"><div id="sel_up_dept_pane" collapsible="false" fit="true" 
    					title="选择上级机构" resizable="false" collapsible="false" minimizable="false" 
    					maximizable="false" noheader="false" closable="false"
    					style="margin:0px;padding:0px;overflow-y:scroll">
    					<ul id="depttree"></ul></div></td>
     				<td>
    					<table style="margin:20px,40px">
			    			<tr height="35px">
    							<td><s:label value="上级机构："></s:label></td>
    							<td><s:textfield id="updeptno" cssStyle="width:250px" 
    								cssClass="text_field_css" disabled="true"></s:textfield>
    								<s:hidden id="updeptno_val" name="curDept.updetpno"/>
    								<label style="width:4px"></label>
    								<label style="color:red">*</label><label>请选择</label></td>
    						</tr>
    						<tr height="35px">
    							<td><s:label value="机构编号：" for="deptno"></s:label></td>
    							<td><input id="deptno" name="curDept.deptno" style="width:250px" 
    								maxlength=<s:property value="%{getText('DEPTNO_LEN')}"/>
    								class="text_field_css"></input><label style="width:4px"></label>
    								<label style="color:red">*</label><label>必输项</label></td>
    						</tr>
    						<tr height="35px">
    							<td><s:label value="机构名称：" for="deptname"></s:label></td>
    							<td><input id="deptname" name="curDept.deptname" style="width:250px"
    								maxlength=<s:property value="%{getText('DEPTNAME_LEN')}"/>
    								class="text_field_css"></input><label style="width:4px"></label>
    								<label style="color:red">*</label><label>必输项</label></td>
    						</tr>
			    			<tr height="28px">
						    	<td align="right"><s:label value="机构类型：" for="typeid"></s:label></td>
			    				<td><s:textfield id="typeid" valueField="typeid" textField="typename" 
    								style="width:250px" editable="false" panelHeight="auto"></s:textfield>
			    				<s:hidden id="typeid_val" name="curDept.depttype"></s:hidden> </td>
			    			</tr>
    						<tr height="35px">
    							<td><s:label value="机构地址：" for="deptaddr"></s:label></td>
    							<td><input id="deptaddr" name="curDept.deptaddr" style="width:250px"
    								maxlength=<s:property value="%{getText('ADDRESS_LEN')}"/>
    								class="text_field_css"></input></td>
    						</tr>
    						<tr height="35px">
    							<td><s:label value="联系电话：" for="telephone"></s:label></td>
    							<td><input id="telephone" name="curDept.telephone" style="width:250px"
    								maxlength=<s:property value="%{getText('TELEPHONE_LEN')}"/>
    								class="text_field_css"></input></td>
    						</tr>
    						<tr height="35px">
    							<td colspan="2" align="center">
            						<button id="save" class="buttons_css" style="width:70px">
            							<label style="70px" class="save_css">保存</label></button>
            						<label style="width:20px"></label>
            						<button id="cancel" class="buttons_css" style="width:70px">
            							<label style="70px" class="cancel_css">返回</label></button>
    							</td>
    						</tr>
    					</table>
    				</td>
    			</tr>
    		</table>
    	</s:form>
    </div>
    </body>
</html>